package xyz.yeidi.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import xyz.yeidi.pojo.Business;
import xyz.yeidi.service.api.BusinessService;
import xyz.yeidi.utils.ServiceFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author JIP
 * @Date 2021-08-07 23:07
 * @Version 1.0
 * @Describe :
 */
@WebServlet("/getBusinessById")
public class GetBusinessByIdServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BusinessService businessService = ServiceFactory.getBusinessService();
        String businessId = request.getParameter("businessId");

        Business business = businessService.getbusinessByid(Integer.valueOf(businessId));
        PrintWriter out = response.getWriter();
        ObjectMapper om = new ObjectMapper();
        if(business==null){
            out.print("no_business");
        }else{
            out.print(om.writeValueAsString(business));
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
